<?php if ($this->_var['full_page']): ?> <?php echo $this->fetch('taobao_pageheader.htm'); ?>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<link href="http://a.tbcdn.cn/??p/global/1.0/global-min.css,p/shop/1.0/base-min.css,p/shop/1.0/mods/c/head/head-min.css,p/shop/1.0/mods/c/foot/foot-min.css,apps/ratemanager/shop/20120628/core/all-min.css?t=20120605" rel="stylesheet" type="text/css" />
<!-- 订单列表 -->
<form>
<div class="list-div" id="listDiv">
    <?php endif; ?>
    <div class="item-list">
        <div class="item-list-bd">
            <table id="J_ListTable">
                <colgroup>
                    <col class="item-list-col0" /><col class="item-list-col1" /><!-- 宝贝 --><col class="item-list-col2" /><!-- 单价(元) --><col class="item-list-col3" /><!-- 数量 --><col class="item-list-col4" /><col class="item-list-col6"><!-- 买家 --><col class="item-list-col7" /><!-- 交易状态 --><col class="item-list-col8" /><!-- 实收款(元) --><col class="item-list-col9" /><!-- 评价 -->
                </colgroup>
                <thead>
                    <tr>
                        <th>
                        	<input onclick="listTable.selectAll(this,'biz_order_id')" type= "checkbox">
                        </th>
                        <th class="item">
                            宝贝
                        </th>
                        <th class="price">
                            单价(元)
                        </th>
                        <th class="num">
                            数量
                        </th>
                        <th class="trouble">
                            售后
                        </th>
                        <th class="contact">
                            买家
                        </th>
                        <th class="trade-status">
                            交易状态
                        </th>
                        <th class="order-price">
                            实收款(元)
                        </th>
                        <th class="remark">
                            评价
                        </th>
                    </tr>
                </thead>
                <?php $_from = $this->_var['order_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('okey', 'order');if (count($_from)):
    foreach ($_from AS $this->_var['okey'] => $this->_var['order']):
?>
                <tbody id="order<?php echo $this->_var['order']['tid']; ?>" class="order">
                    <tr class="sep-row">
                        <td colspan="9">
                        </td>
                    </tr>
                    <tr class="order-hd">
                        <td colspan="9">
                            <input class="selector" type="checkbox" id="cb<?php echo $this->_var['order']['tid']; ?>" name="biz_order_id" value="<?php echo $this->_var['order']['tid']; ?>" />
                            <div class="basic-info">
                                <span class="order-num">
                                    <label for="cb145753424627296">
                                        订单编号：<?php echo $this->_var['order']['tid']; ?>
                                    </label>
                                </span>
                                <span class="deal-time">成交时间：<?php echo $this->_var['order']['created']; ?></span>
                            </div>
                            <div class="more-info">
                                <a class="J_MemoFlag memo-flag" href="javascript:showmemo(<?php echo $this->_var['order']['tid']; ?>,<?php echo $this->_var['order']['seller_flag']; ?>,<?php if ($this->_var['order']['seller_memo'] == null): ?>''<?php else: ?>'<?php echo $this->_var['order']['seller_memo']; ?>'<?php endif; ?>)"><img alt="" src="http://a.tbcdn.cn/sys/common/icon/trade/op_memo_<?php echo $this->_var['order']['seller_flag']; ?>.png"></a>
                            </div><input type="hidden" name="sellerId" value="" /><input type="hidden" name="buyerId" value="" />
                        </td>
                    </tr><!--start 子订单list  start-->
                    <tr id="item<?php echo $this->_var['order']['tid']; ?>" class="order-item
 last
">
                        <td colspan="2" class="item">
                            <div class="pic-info">
                                <div class="pic s50">
                                    <a hidefocus="true"  title="查看宝贝详情" href="http://item.taobao.com/item.htm?id=<?php echo $this->_var['order']['num_iid']; ?>"><img alt="查看宝贝详情" src="<?php echo $this->_var['order']['pic_path']; ?>" /></a>
                                </div>
                            </div>
                            <div class="txt-info">
                                <div class="desc">
                                    <a hidefocus="true" href="http://item.taobao.com/item.htm?id=<?php echo $this->_var['order']['num_iid']; ?>" title="查看宝贝详情" ><?php echo $this->_var['order']['title']; ?></a>
                                    <span class="good-icons"></span>
                                </div>
                            </div>
                        </td>
                        <td class="price" title="<?php echo $this->_var['order']['payment']; ?>">
                            <?php echo $this->_var['order']['payment']; ?>
                        </td>
                        <td class="num" title="<?php echo $this->_var['order']['num']; ?>">
                            <?php echo $this->_var['order']['num']; ?>
                        </td>
                        <td class="trouble">
                        </td>
                        <td class="contact" rowspan="1" sumrows="1">
                            <a class="nickname" href='http://www.taobao.com/webww/ww.php?ver=3&touid=<?php echo urlencode($this->_var['order']['buyer_nick']); ?>&siteid=cntaobao&status=1&charset=utf-8' ><?php echo $this->_var['order']['buyer_nick']; ?></a>
                            <span class="name J_UserInfo" data=""><?php echo $this->_var['order']['receiver_name']; ?></span>
                            <span class="J_WangWang" data-nick="love5颜6色" data-display="inline" data-item="$bizOrder.itemID:199531605027296"><a  href='http://www.taobao.com/webww/ww.php?ver=3&touid=<?php echo urlencode($this->_var['order']['buyer_nick']); ?>&siteid=cntaobao&status=1&charset=utf-8'><img border="0" src='http://amos.alicdn.com/realonline.aw?v=2&uid=<?php echo urlencode($this->_var['order']['buyer_nick']); ?>&site=cntaobao&s=1&charset=utf-8' alt="点击这里给我发消息" /></a></span>
                        </td>
                        <td class="trade-status" rowspan="1" sumrows="1">
                            <a href="javascript:show_order_info(<?php echo $this->_var['order']['tid']; ?>)" ><strong class="J_TradeStatus status todo h"><?php echo $this->_var['order']['status']; ?></strong></a>
                            <a href="javascript:show_order_info(<?php echo $this->_var['order']['tid']; ?>)" class="detail-link" >详情</a>
                            <div class="trade-actions">
                                <?php if ($this->_var['order']['status'] == "买家已付款"): ?> <span class="skin-blue"><a class="small-btn" style="color:white;text-decoration:none;" href="javascript:delivery(<?php echo $this->_var['order']['tid']; ?>)" >发货</a></span>
                                <?php endif; ?>
                            </div>
                        </td>
                        <td class="order-price" rowspan="1" sumrows="1">
                            <strong class="J_OrderPrice"><?php echo $this->_var['order']['payment']; ?></strong>
                            <div class="post-info">
                                <span class="post-type">(<?php echo $this->_var['order']['post_fee']; ?>)</span>
                            </div>
                        </td>
                        <td class="remark" rowspan="1" sumrows="1">
                            <div class="remark-status">
                                <!--<?php if ($this->_var['order']['status'] == '交易成功'): ?>
                                <?php if ($this->_var['order']['buyer_rate'] == 1 && $this->_var['order']['seller_rate'] == 1): ?><a href="javascript:rate('<?php echo $this->_var['order']['tid']; ?>')">双方已评</a>
                                <?php else: ?>
                                <?php if ($this->_var['order']['buyer_rate'] == 1): ?><a href="javascript:rate('<?php echo $this->_var['order']['tid']; ?>')">买家已评</a>
                                <?php endif; ?>
                                <?php if ($this->_var['order']['seller_rate'] == 1): ?><a href="javascript:rate('<?php echo $this->_var['order']['tid']; ?>')">我已评价</a>
                                <?php else: ?><a href="javascript:rate('<?php echo $this->_var['order']['tid']; ?>')">评价</a>
                                <?php endif; ?>
                                <?php endif; ?>
                                <?php endif; ?>-->
                            </div>
                        </td>
                    </tr>
                    <!--end 子订单list  end-->
                </tbody>
                <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
            </table>
        </div>
    </div>
    <!-- 分页 -->
    <table id="page-table" cellspacing="0">
        <tr>
        	<?php if ($this->_var['status'] == "payed"): ?> 
	        	<td>
	        		<div>
			        	<a class="small-btn" style="color:white;text-decoration:none;" href= "javascript:dodelivery(this,'biz_order_id')">批量发货</a>
			        </div>
	        	<td>
        	<?php endif; ?>
            <td align="right" nowrap="true">
                <?php echo $this->fetch('page.htm'); ?>
            </td>
        </tr>
    </table>
    <?php if ($this->_var['full_page']): ?>
</div>
</form>
<div id="memo" style="display:none;">
    <table class="memo-editor">
        <tbody>
            <tr class="flag-options">
                <th>
                    标记：
                </th>
                <td>
                    <ul>
                        <li>
                            <input type="radio" id="flag1" name="flag" value="1">
                            <label class="memo-flag" for="flag1">
                                <img src="http://a.tbcdn.cn/sys/common/icon/trade/op_memo_1.png">
                            </label>
                        </li>
                        <li>
                            <input type="radio" id="flag2" name="flag" value="2">
                            <label class="memo-flag" for="flag2">
                                <img src="http://a.tbcdn.cn/sys/common/icon/trade/op_memo_2.png">
                            </label>
                        </li>
                        <li>
                            <input type="radio" id="flag3" name="flag" value="3">
                            <label class="memo-flag" for="flag3">
                                <img src="http://a.tbcdn.cn/sys/common/icon/trade/op_memo_3.png">
                            </label>
                        </li>
                        <li>
                            <input type="radio" id="flag4" name="flag" value="4">
                            <label class="memo-flag" for="flag4">
                                <img src="http://a.tbcdn.cn/sys/common/icon/trade/op_memo_4.png">
                            </label>
                        </li>
                        <li>
                            <input type="radio" id="flag5" name="flag" value="5">
                            <label class="memo-flag" for="flag5">
                                <img src="http://a.tbcdn.cn/sys/common/icon/trade/op_memo_5.png">
                            </label>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr>
                <th>
                    备忘信息：
                </th>
                <td>
                    <label for="memo" class="memo-textarea-label" style="visibility: hidden;">
                        备忘信息作为你对这笔订单的备忘记录，仅自己可见。
                    </label>
                    <textarea id="txtmemo" name="memo" cols="120" rows="8">
                    </textarea>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<div id="rate" style="display:none;">
    <table cellpadding="2px" cellspacing="2px" style="border:solid 1px gray;border-collapse:collapse;">
        <tr>
            <td rowspan="2">
                <label id="lblRateResult">
                </label>
            </td>
        </tr>
        <tr>
            <td>
                <label id="lblRateContent">
                </label>
            </td>
            <td>
                <label id="lblRateCreated">
                </label>
            </td>
        </tr>
    </table>
    <table cellpadding="2px" cellspacing="2px" style="margin-top:5px;border:solid 1px gray;border-collapse:collapse;">
        <tr>
            <td>
                <input type="radio" name="result" checked="checked" value="good">好评&nbsp;&nbsp;<input type="radio" name="result" value="neutral">中评&nbsp;&nbsp;<input type="radio" name="result" value="bad">差评&nbsp;&nbsp;
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" id="content"/>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
            listTable.recordCount = <?php echo $this->_var['record_count']; ?>;
            listTable.pageCount = <?php echo $this->_var['page_count']; ?>;
            <?php $_from = $this->_var['filter']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('key', 'item');if (count($_from)):
    foreach ($_from AS $this->_var['key'] => $this->_var['item']):
?>
            	listTable.filter.<?php echo $this->_var['key']; ?> = '<?php echo $this->_var['item']; ?>';
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
            
            var d,t;
			function dodelivery(obj,chk){
	            if (chk == null){
	            	chk = 'checkboxes';
	            }
	                                
	            var elems = document.getElementsByTagName("INPUT");
	            var tids = '';
	            for (var i=0; i < elems.length; i++){
		            if (elems[i].name == chk || elems[i].name == chk + "[]"){
			            if(elems[i].checked){
			            	tids += elems[i].value + ',';
			            }
		            }
	            }
	                                  
	            if(tids.length == 0){
		            alert('未选择任何订单');
		            return false;
	            }
				tids = tids.substr(0,tids.length - 1);
				
				delivery(tids);
				//alert(tids);
            }
    		function getVByName(nm){
	            var tt = document.getElementsByName(nm);
	            for (var iIndex = 0; iIndex < tt.length ; iIndex++ )
	            {
	                if(tt[iIndex].checked)
	                {
	                    return tt[iIndex].value;
	                    break;
	                }
	            }
        	}
            	function rate(tid){
        			Ajax.call('taobao_order.php?act=order_rate_get&tid='+tid, '', rateGetCallback , 'POST', 'JSON');
        			
            		d = art.dialog({
            			title:'评价',
            			content:document.getElementById('rate'),
            			ok:function(){
            				var result = getVByName('result');
            				var content = document.getElementById('content').value;
            				t = art.dialog({title:'正在提交'});
            				Ajax.call('taobao_order.php?act=order_rate&tid='+tid+'&result='+result+'&content='+content, '', rateCallback , 'POST', 'JSON');
            				return false;
            			},
            			cancel:true
            		});
            	}
            	
        		function rateGetCallback(data){
        			if(data.error == 0){
        				document.getElementById('lblRateContent').innerHTML = data.content;
        				document.getElementById('lblRateCreated').innerHTML = data.created;
        				var result;
        				if (data.result == 'good') {result = '好评'};
        				if (data.result == 'neutral') {result = '中评'};
        				if (data.result == 'bad') {result = '差评'};
        				document.getElementById('lblRateResult').innerHTML = result;
        			}
        		}
        		
            	function rateCallback(data){
					d.close();
            		t.close();
            		if (data.error > 0)
                    {
                        if (data.code == "27") {
            				art.dialog({
            	        		icon:'face-sad',
            	        		content:'淘宝帐户已过期，请重新登录',
            	        		ok:function(){
            	        			window.top.location.href = 'http://container.api.taobao.com/container?appkey=<?php echo $this->_var['appkey']; ?>&encode=utf-8';
            	        		},
            	        		cancel:true
            	        	});
            			}else{
            				art.dialog({
            	        		icon:'error',
            	        		content:data.message,
            	        		ok:true
            	        	});
            			}
                    }else{
            			art.dialog({content:'评价成功',icon:'succeed',time:"3"});
            			window.location.reload(true);
            		}
            	}
            
                function showmemo(tid,flag,memo){
            		if (flag != 0) { 
            			document.getElementById('flag'+flag).setAttribute("checked","checked");
            		};    	
            		document.getElementById('txtmemo').value = memo;
                    d = $.dialog({
                        title:'添加备注',
                        content:document.getElementById("memo"),
            			ok:function(){
            				addmemo(tid);
            			},
                        cancel:true,
                    });
                }
            	
            	function addmemo(tid){
            		t = art.dialog({title:'正在提交'});
            		var memo = document.getElementById('txtmemo').value;
            		var flag = getRadioValueByName('flag');
            		if (isNaN(flag)) {flag=0};
            		
            		Ajax.call('taobao_order.php?act=order_memo_add&tid='+tid+'&memo='+memo+'&flag='+flag, '', order_memo_callback , 'POST', 'JSON');
            		return false;
            	}
            
            	function order_memo_callback(data){
            		if (data.error > 0)
                    {
                        if (data.code == "27") {
            				t.close();
            				art.dialog({
            	        		icon:'face-sad',
            	        		content:'淘宝帐户已过期，请重新登录',
            	        		ok:function(){
            	        			window.top.location.href = 'http://container.api.taobao.com/container?appkey=<?php echo $this->_var['appkey']; ?>&encode=utf-8';
            	        		},
            	        		cancel:true
            	        	});
            				d.content(document.getElementById('memo'));
            			}else if(data.code == '520'){
            				var memo = document.getElementById('txtmemo').value;
            				var flag = getRadioValueByName('flag');
            				Ajax.call('taobao_order.php?act=order_memo_update&tid='+data.tid+'&memo='+memo+'&flag='+flag, '', order_memo_callback , 'POST', 'JSON');
            			}else{
            				t.close();
            				art.dialog({
            	        		icon:'error',
            	        		content:data.message,
            	        		ok:true
            	        	});
            			}
                    }else{
            			t.close();
            			art.dialog({icon:'succeed',content:'备注成功',time:'2'});
            			window.location.reload(true);
            		}
            	}
            	function getRadioValueByName(nm){
                    var tt = document.getElementsByName(nm);
                    for (var iIndex = 0; iIndex < tt.length ; iIndex++ )
                    {
                        if(tt[iIndex].checked)
                        {
                            return tt[iIndex].value;
                        }
                    }
                };
            	function order_import(){
            		 Ajax.call('taobao_order.php?act=order_import&'+Math.random(), '', order_import_callback , 'POST', 'JSON');
            		
            		//var url = 'taobao_order.php?act=order_import';
            		//send(url,order_import_callback)
            
                    d = art.dialog({
                        title: "导入订单",
                        cancel:true
                    });
            	}
            	function order_import_callback(data){
            		/*if (data.error == 2) {
            			d.content('正在处理...  ' + data.currNum + ' / ' + data.total);
            			return;
            		}*/
            		d.close();
            		if (data.error != 0)
                    {
                        if (data.code == "27") {
            				art.dialog({
            	        		icon:'face-sad',
            	        		content:'淘宝帐户已过期，请重新登录',
            	        		ok:function(){
            	        			window.top.location.href = 'http://container.api.taobao.com/container?appkey=<?php echo $this->_var['appkey']; ?>&encode=utf-8';
            	        		},
            	        		cancel:true
            	        	});
            			}else{
            				art.dialog({
            	        		icon:'error',
            	        		content:data.message,
            	        		ok:true
            	        	});
            			}
                    }else{
            			art.dialog({content:'恭喜,导入成功!',icon:'succeed',ok:true});
            			window.location.reload(true);
            		}
            	}
                function show_order_info(tid){
                    Ajax.call('taobao_order.php?act=order_info&tid='+tid, '', response_order_info , 'POST', 'JSON');
            
                    d = art.dialog({
                        title: "订单详情",
                        cancel:true
                    });
                }
            
                function response_order_info(data){
                    if (data.error > 0)
                    {
                        d.content(data.message);
                        return;
                    }
                    d.content(data.content);
                }
            
                function delivery(tid){
                    Ajax.call('taobao_order.php?act=order_delivery&tid='+tid, '', deliveryCallback , 'POST', 'JSON');
            
                    d = art.dialog({
                        title: "发货处理"
                    });
                }
            
                function deliveryCallback(data){
                	d.close();
                    if(data.error == "0"){
                    	art.dialog({
                    		icon:'succeed',
                    		content:'发货成功',
                    		ok:function(){
            					window.location.reload(true);
            				}
                    	});
                    }else if(data.code == "27"){
                    	art.dialog({
                    		icon:'face-sad',
                    		content:'淘宝帐户已过期，请重新登录',
                    		ok:function(){
                    			window.top.location.href = 'http://container.api.taobao.com/container?appkey=<?php echo $this->_var['appkey']; ?>&encode=utf-8';
                    		},
                    		cancel:true
                    	});
                    }else{
                    	art.dialog({
                    		icon:'error',
                    		content:data.message,
                    		ok:true
                    	});			
                    }
                }
            
                var clear = function () {
                    document.getElementById("tab0").className = "";
                    document.getElementById("tab1").className = "";
                    document.getElementById("orderinfo").style.display = "none";
                    document.getElementById("addrinfo").style.display = "none";
                };
                var orderinfo = function (obj) {
                    clear();
                    obj.className = "current";
                    document.getElementById("orderinfo").style.display = "block";
                };
                var addrinfo = function (obj) {
                    clear();
                    obj.className = "current";
                    document.getElementById("addrinfo").style.display = "block";
                };
            	
            	 function send(url,callback){
                        var xhr = new window.XMLHttpRequest();
                        if(!window.XMLHttpRequest){
                                try {
                                    xhr = new window.ActiveXObject("Microsoft.XMLHTTP");
                                } catch(e) {}
                        }
                        xhr.open("post",url);
                        var oldSize=0;
                        xhr.onreadystatechange = function(){
                            if(xhr.readyState > 2){         
                              var tmpText = xhr.responseText.substring(oldSize); 
            				  var j =  xhr.responseText.toJSONString();
                              oldSize = xhr.responseText.length;
                              if(tmpText.length > 0 ){
                                callback(j);
                             }
                            }
                        }
                        xhr.send(null);
            	}
</script>
 <?php echo $this->fetch('taobao_pagefooter.htm'); ?> <?php endif; ?>